#tag layout_block("css_page_level")
<link rel="stylesheet" type="text/css" href="${CONTEXT_PATH}/assets/global/plugins/select2/select2.css"/>
<link href="${CONTEXT_PATH}/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.css" rel="stylesheet"
      type="text/css"/>
<link href="${CONTEXT_PATH}/assets/admin/pages/css/profile.css" rel="stylesheet" type="text/css"/>
<link href="${CONTEXT_PATH}/assets/admin/pages/css/tasks.css" rel="stylesheet" type="text/css"/>
#end
#tag layout_block("js_page_level")
<script type="text/javascript" src="${CONTEXT_PATH}/assets/global/plugins/select2/select2.min.js"></script>
<script type="text/javascript"
        src="${CONTEXT_PATH}/assets/global/plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script type="text/javascript"
        src="${CONTEXT_PATH}/assets/global/plugins/jquery-validation/js/additional-methods.min.js"></script>
<script src="${CONTEXT_PATH}/assets/global/plugins/bootstrap-growl/jquery.bootstrap-growl.min.js"></script>
<script src="${CONTEXT_PATH}/assets/global/plugins/bootstrap-maxlength/bootstrap-maxlength.min.js"
        type="text/javascript"></script>

<script src="${CONTEXT_PATH}/assets/global/plugins/bootstrap-fileinput/bootstrap-fileinput.js"
        type="text/javascript"></script>
<script src="${CONTEXT_PATH}/assets/global/plugins/jquery.sparkline.min.js" type="text/javascript"></script>
<script src="${CONTEXT_PATH}/assets/global/plugins/bootstrap-confirmation/bootstrap-confirmation.min.js"
        type="text/javascript"></script>
<script src="${CONTEXT_PATH}/assets/global/scripts/jquery.easyui.min.js"></script>

<script src="${CONTEXT_PATH}/assets/global/scripts/rsa/RSA.js" type="text/javascript"></script>
<script src="${CONTEXT_PATH}/assets/global/scripts/rsa/BigInt.js" type="text/javascript"></script>
<script src="${CONTEXT_PATH}/assets/global/scripts/rsa/Barrett.js" type="text/javascript"></script>
#end

#tag layout_block("content")
<div class="row">
    <div class="col-md-12">
        <div class="portlet light bordered">
            <div class="portlet-title tabbable-line">
                <div class="caption">
                    <span class="caption-subject font-blue bold uppercase">${getMessage('net.mayee.alice.web.sys.user.user_info')}</span>
                    <span class="caption-helper"></span>
                </div>
                ${printUserEditActions(user.uuid, user.statusCode)}
            </div>
            <div class="portlet-body form">
                <div class="row">
                    <div class="col-md-3 col-sm-3 col-xs-3">
                        <ul class="nav nav-tabs tabs-left">
                            <li class="active">
                                <a href="#tab_1" data-toggle="tab">
                                    ${getMessage('net.mayee.alice.web.sys.user.base_info')} </a>
                            </li>
                            <li>
                                <a href="#tab_2" data-toggle="tab">
                                    ${getMessage('net.mayee.alice.web.sys.user.photo')} </a>
                            </li>
                            <li>
                                <a href="#tab_3" data-toggle="tab">
                                    ${getMessage('net.mayee.alice.web.sys.user.reset_password')} </a>
                            </li>
                        </ul>
                    </div>
                    <div class="col-md-9 col-sm-9 col-xs-9">
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_1">
                                <!-- BEGIN FORM-->
                                <form id="form_1" modelAttribute="user" class="form-horizontal" method="post">
                                    <input type="hidden" value="${user.uuid}" name="uuid">

                                    <div class="form-body">
                                        <div class="alert alert-danger display-hide" data-text="${getMessage('net.mayee.alice.alert.default_msg')}">
                                            <button class="close" data-close="alert"></button>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.username')}</label>

                                            <div class="col-md-6">
                                                <div class="input-icon right">
                                                    <i class="fa"></i>
                                                    <input type="text" class="form-control" readonly
                                                           placeholder="${user.loginName}"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">${getMessage('net.mayee.alice.web.sys.user.name')}</label>

                                            <div class="col-md-6">
                                                <div class="input-icon right">
                                                    <i class="fa"></i>
                                                    <input type="text" class="form-control" value="${user.name}"
                                                           id="name"
                                                           name="name"
                                                           maxlength="10"
                                                           placeholder="${getMessage('net.mayee.alice.web.sys.user.name.tip')}">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">${getMessage('net.mayee.alice.web.sys.user.phone')}</label>

                                            <div class="col-md-6">
                                                <input type="text" class="form-control" value="${user.phone}" id="phone"
                                                       name="phone"
                                                       maxlength="20"
                                                       placeholder="${getMessage('net.mayee.alice.web.sys.user.phone.tip')}">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.email')}</label>

                                            <div class="col-md-6">
                                                <div class="input-icon right">
                                                    <i class="fa"></i>
                                                    <input type="text" class="form-control" value="${user.email}"
                                                           id="email"
                                                           name="email" maxlength="40" placeholder="${getMessage('net.mayee.alice.web.sys.user.email.tip')}"/>
                                                </div>
                                            </div>
                                        </div>
                                        #set(disabledStr = "disabled")
                                        #if(user.isNotAdmin())
                                        #set(disabledStr = "")
                                        #set(roleTipStr = getMessage('net.mayee.alice.web.sys.user.role.tip'))
                                        #end
                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.role')}</label>

                                            <div class="col-md-6">
                                                <input type="hidden" id="roleSel" value="${rolesChooseString}" ${disabledStr}
                                                       name="roleSel"
                                                       placeholder="${getMessage('net.mayee.alice.web.sys.user.role.tip2')}" class="form-control select2">
                                                <span class="help-block"> ${roleTipStr} </span>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.status')}</label>

                                            <div class="col-md-6">
                                                #set(ckStr = "checked")
                                                #if(user.statusCode == 0)
                                                #set(ckStr = "")
                                                #end
                                                <input type="checkbox" class="make-switch" ${ckStr} name="statusCode" value="3"
                                                       data-on-color="success" data-off-color="warning"
                                                       data-on-text="&nbsp;&nbsp;${getMessage('net.mayee.alice.code.user_status.3')}&nbsp;&nbsp;" data-off-text="&nbsp;&nbsp;${getMessage('net.mayee.alice.code.user_status.0')}&nbsp;&nbsp;">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">${getMessage('net.mayee.alice.web.sys.user.language')}</label>

                                            <div class="col-md-6">
                                                <div class="btn-group" data-toggle="buttons">
                                                    #for(lag : lagList)
                                                    #if(user.language.code == lag.code)
                                                    <label class="btn green active">
                                                        <input type="radio" class="toggle" name="language.id" checked
                                                               value="${lag.id}">
                                                        ${lag.name}
                                                    </label>
                                                    #else
                                                    <label class="btn green">
                                                        <input type="radio" class="toggle" name="language.id"
                                                               value="${lag.id}">
                                                        ${lag.name}
                                                    </label>
                                                    #end
                                                    #end
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-actions">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                #if(!isPermission("user:U") || user.isAdmin())
                                                #set(disabledSaveStr="disabled")
                                                #end
                                                <button type="submit" class="btn blue" ${disabledSaveStr}><i class="fa fa-save"></i> ${getMessage('net.mayee.alice.btn.save')}
                                                </button>
                                                <button type="button" class="btn default"
                                                        onclick="javascript:window.location.href='${CONTEXT_PATH}/sdm/sys/user/R'">
                                                    ${getMessage('net.mayee.alice.btn.cancel')}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <!-- END FORM-->
                            </div>
                            <div class="tab-pane fade" id="tab_2">
                                <form id="form_2" action="${CONTEXT_PATH}/sys/user/ajax/PUL"
                                      enctype="multipart/form-data" method="post">
                                    <input type="hidden" value="${user.uuid}" name="uid">

                                    <div class="alert alert-danger display-hide">
                                        <button class="close" data-close="alert"></button>
                                    </div>
                                    <div class="form-group">
                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                            <div class="fileinput-new thumbnail"
                                                 style="width: 200px; height: 200px;">
                                                <img src="${CONTEXT_PATH}/${user.photoImg}" alt=""/>
                                            </div>
                                            <div class="fileinput-preview fileinput-exists thumbnail"
                                                 style="max-width: 200px; max-height: 200px;">
                                            </div>
                                            <div>
                                                    <span class="btn default btn-file">
                                                        <span class="fileinput-new"> ${getMessage('net.mayee.alice.btn.choose_image')} </span>
                                                        <span class="fileinput-exists"> ${getMessage('net.mayee.alice.btn.modify')} </span>
                                                        <input type="file" name="photoImg" onchange="loadPhoto(this)"/>
                                                    </span>
                                                <a href="javascript:;" class="btn default fileinput-exists"
                                                   data-dismiss="fileinput"> ${getMessage('net.mayee.alice.btn.delete')} </a>
                                            </div>
                                        </div>
                                        <blockquote class="clearfix margin-top-20" style="font-size: 13px;">
                                            <span>${getMessage('net.mayee.alice.web.sys.user.choose_image.tip')}</span>
                                        </blockquote>
                                    </div>
                                    <div class="margin-top-10">
                                        <div class="row">
                                            <div class="col-md-12">
                                                #if(!isPermission("user:UPDATE_PHOTO"))
                                                #set(disabledPhotoStr="disabled")
                                                #end
                                                <button type="button" ${disabledPhotoStr} id="savePhotoBtn" onclick="submitForm()" class="btn blue"><i
                                                        class="fa fa-save"></i> ${getMessage('net.mayee.alice.btn.save')}
                                                </button>
                                                <button type="button" class="btn default"
                                                        onclick="javascript:window.location.href='${CONTEXT_PATH}/sdm/sys/user/R'">
                                                    ${getMessage('net.mayee.alice.btn.cancel')}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="tab-pane fade" id="tab_3">
                                <form id="form_3" class="form-horizontal" method="post">
                                    <input type="hidden" value="${user.uuid}" name="uid">
                                    <input type="hidden" id="rsa_m" value="${rsa_modulus}">
                                    <input type="hidden" id="rsa_e" value="${rsa_exponent}">
                                    <div class="alert alert-info">
                                        ${getMessage('net.mayee.alice.web.sys.user.new_password_tip')}
                                    </div>
                                    <div class="alert alert-danger display-hide">
                                        <button class="close" data-close="alert"></button>
                                    </div>
                                    <div class="form-body">
                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.new_password')}<span class="required"> * </span>
                                            </label>

                                            <div class="col-md-6">
                                                <div class="input-icon right">
                                                    <i class="fa"></i>
                                                    <input type="password" class="form-control" name="resetPassword1"
                                                           id="resetPassword1"
                                                           maxlength="16" placeholder="${getMessage('net.mayee.alice.web.sys.user.password.tip')}"/>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="control-label col-md-3">${getMessage('net.mayee.alice.web.sys.user.confirm_password')}<span class="required"> * </span>
                                            </label>

                                            <div class="col-md-6">
                                                <div class="input-icon right">
                                                    <i class="fa"></i>
                                                    <input type="password" class="form-control" id="resetPassword2"
                                                           name="resetPassword2" maxlength="16"
                                                           placeholder="${getMessage('net.mayee.alice.web.sys.user.confirm_password.tip')}"/>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-actions">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                #if(!isPermission("user:RESET_PASSWORD"))
                                                #set(RESET_PASSWORD_disabledStr = " disabled='disabled' ")
                                                #end
                                                <button type="submit" id="resetBtn" class="btn red"
                                                        data-toggle="confirmation"
                                                        ${RESET_PASSWORD_disabledStr}
                                                        title="${getMessage('net.mayee.alice.alert.reset')}"
                                                        data-btn-ok-label="${getMessage('net.mayee.alice.global.yes')}"
                                                        data-btn-cancel-label="${getMessage('net.mayee.alice.global.no')}"
                                                        data-singleton="true"><i class="fa fa-retweet"></i> ${getMessage('net.mayee.alice.btn.reset')}
                                                </button>
                                                <button type="button" class="btn default"
                                                        onclick="javascript:window.location.href='${CONTEXT_PATH}/sdm/sys/user/R'">
                                                    ${getMessage('net.mayee.alice.btn.cancel')}
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
#end

#tag layout_block("script")
<script>
    var error2;
    jQuery(document).ready(function () {
        var list = ['name', 'phone', 'email'];
        Alice.regMaxLength(list);
        Alice.addRoleSelForValidator();

        var roleSel = $("#roleSel");
        if(roleSel){
            roleSel.select2({
                tags: [${rolesString}]
            });
        }

        var el = $('.portlet');
        var formObj = $('#form_1');
        var error = $('.alert-danger', formObj);

        formObj.validate({
            errorElement: 'span',
            errorClass: 'help-block help-block-error',
            focusInvalid: false,
            ignore: "",
            rules: {
                name: {
                    minlength: 2,
                    maxlength: 10,
                    required: true
                },
                email: {
                    required: true,
                    email: true
                },
                roleSel: {
                    required: true,
                    checkRoleSel: 3
                }
            },

            invalidHandler: function (event, validator) {
                Alice.showDefaultFailAlert(error);
            },

            errorPlacement: function (error, element) {
                var icon = $(element).parent('.input-icon').children('i');
                icon.removeClass('fa-check').addClass("fa-warning");
                icon.attr("data-original-title", error.text()).tooltip({'container': 'body'});
            },

            highlight: function (element) {
                $(element)
                        .closest('.form-group').removeClass("has-success").addClass('has-error');
            },

            unhighlight: function (element) {
            },

            success: function (label, element) {
                var icon = $(element).parent('.input-icon').children('i');
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                icon.removeClass("fa-warning").addClass("fa-check");
            },

            submitHandler: function (form) {
                error.hide();
                Metronic.blockUI({
                    target: el,
                    animate: true,
                    overlayColor: 'blue'
                });
                $.ajax({
                    type: "POST",
                    url: "${CONTEXT_PATH}/sys/user/ajax/U",
                    data: formObj.serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        Metronic.unblockUI(el);
                        if (res.msgid == 'SSSS') {
                            Alice.showDefaultSuccessGrowl(res.msgdesc);
                        } else {
                            Alice.showDefaultFailAlert(error, res);
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        Metronic.unblockUI(el);
                        Alice.showDefaultWarningGrowl("${getMessage('net.mayee.alice.error.data_error')}");
                    }
                });
            }
        });

        var formObj2 = $('#form_2');
        error2 = $('.alert-danger', formObj2);

        $('#form_2').form({
            url: '${CONTEXT_PATH}/sys/user/ajax2/PUL',
            onSubmit: function () {
                error2.hide();
                Metronic.blockUI({
                    target: el,
                    animate: true,
                    overlayColor: 'blue'
                });
            },
            success: function (res) {
                Metronic.unblockUI(el);
                var result = eval('(' + res + ')');
                if (result.msgid == 'SSSS') {
                    Alice.showDefaultSuccessGrowl(result.msgdesc);
                } else {
                    Alice.showDefaultFailAlert(error2, result);
                }
//                console.info(map);
            }
        });

        var formObj3 = $('#form_3');
        var error3 = $('.alert-danger', formObj3);
        var rsa_m = $("#rsa_m");
        var rsa_e = $("#rsa_e");
        var pwObj1 = $("#resetPassword1");
        var pwObj2 = $("#resetPassword2");

        formObj3.validate({
            errorElement: 'span',
            errorClass: 'help-block help-block-error',
            focusInvalid: false,
            ignore: "",
            rules: {
                resetPassword1: {
                    minlength: 4,
                    maxlength: 16,
                    required: true
                },
                resetPassword2: {
                    required: true,
                    equalTo: "#resetPassword1"
                }
            },

            invalidHandler: function (event, validator) {
                Alice.showDefaultFailAlert(error);
            },

            errorPlacement: function (error, element) {
                var icon = $(element).parent('.input-icon').children('i');
                icon.removeClass('fa-check').addClass("fa-warning");
                icon.attr("data-original-title", error.text()).tooltip({'container': 'body'});
            },

            highlight: function (element) {
                $(element)
                        .closest('.form-group').removeClass("has-success").addClass('has-error');
            },

            unhighlight: function (element) {
            },

            success: function (label, element) {
                var icon = $(element).parent('.input-icon').children('i');
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success');
                icon.removeClass("fa-warning").addClass("fa-check");
            },

            submitHandler: function (form) {
                pwObj1.val(Alice.encryptRSA(rsa_m.val(), rsa_e.val(), pwObj1.val()));
                pwObj2.val(Alice.encryptRSA(rsa_m.val(), rsa_e.val(), pwObj2.val()));
                error3.hide();
                Metronic.blockUI({
                    target: el,
                    animate: true,
                    overlayColor: 'blue'
                });
                $.ajax({
                    type: "POST",
                    url: "${CONTEXT_PATH}/sys/user/ajax/RPW",
                    data: formObj3.serialize(),
                    dataType: "JSON",
                    success: function (res) {
                        Metronic.unblockUI(el);
                        if (res.msgid == 'SSSS') {
                            Alice.showDefaultSuccessGrowl(res.msgdesc);
                            Alice.resetValidatorForm(form);
                        } else {
                            Alice.showDefaultFailAlert(error, res);
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        Metronic.unblockUI(el);
                        Alice.showDefaultWarningGrowl("${getMessage('net.mayee.alice.error.data_error')}");
                    }
                });
            }
        });

        $('#onABtn').click(function () {
            bootbox.dialog({
                message:"<div class=\"row\">" +
                            "<div class=\"col-md-12 margin-top-10\">" +
                                "${getMessage('net.mayee.alice.alert.on_admin')}" +
                            "</div>" +
                        "</div>" +
                        "<div class=\"row\">" +
                            "<div class=\"col-md-12\">" +
                                "<div class=\"alert alert-success no-margin margin-top-20 \">" +
                                    "${getMessage('net.mayee.alice.note.on_admin')}" +
                                "</div>" +
                            "</div>" +
                        "</div>",
                title: "${getMessage('net.mayee.alice.alert.title.on_admin')}",
                buttons: {
                    danger: {
                        label: "${getMessage('net.mayee.alice.btn.confirm')}",
                        className: "red",
                        callback: function () {
                            Metronic.blockUI({
                                target: el,
                                animate: true,
                                overlayColor: 'red'
                            });
                            $.ajax({
                                type: "POST",
                                url: "${CONTEXT_PATH}/sys/user/ajax/OnA/${user.uuid}",
                                data: "",
                                dataType: "JSON",
                                success: function (res) {
                                    if (res.msgid == 'SSSS') {
                                        bootbox.alert("${getMessage('net.mayee.alice.alert.title.success')}", function () {
                                            window.location.href = "${CONTEXT_PATH}/sdm/sys/user/R";
                                        });
                                    } else {
                                        Metronic.unblockUI(el);
                                        Alice.showDefaultFailAlert(error, res);
                                    }
                                },
                                error: function (xhr, ajaxOptions, thrownError) {
                                    Metronic.unblockUI(el);
                                    Alice.showDefaultWarningGrowl("${getMessage('net.mayee.alice.error.data_error')}");
                                }
                            });
                        }
                    },
                    main: {
                        label: "${getMessage('net.mayee.alice.btn.cancel')}",
                        className: "default"
                    }
                }
            });
        });

        $('#offABtn').click(function () {
            bootbox.dialog({
                message:"<div class=\"row\">" +
                "<div class=\"col-md-12 margin-top-10\">" +
                "${getMessage('net.mayee.alice.alert.off_admin')}" +
                "</div>" +
                "</div>" +
                "<div class=\"row\">" +
                "<div class=\"col-md-12\">" +
                "<div class=\"alert alert-success no-margin margin-top-20 \">" +
                "${getMessage('net.mayee.alice.note.off_admin')}" +
                "</div>" +
                "</div>" +
                "</div>",
                title: "${getMessage('net.mayee.alice.alert.title.off_admin')}",
                buttons: {
                    danger: {
                        label: "${getMessage('net.mayee.alice.btn.confirm')}",
                        className: "red",
                        callback: function () {
                            Metronic.blockUI({
                                target: el,
                                animate: true,
                                overlayColor: 'red'
                            });
                            $.ajax({
                                type: "POST",
                                url: "${CONTEXT_PATH}/sys/user/ajax/OffA/${user.uuid}",
                                data: "",
                                dataType: "JSON",
                                success: function (res) {
                                    if (res.msgid == 'SSSS') {
                                        bootbox.alert("${getMessage('net.mayee.alice.alert.title.success')}", function () {
                                            window.location.href = "${CONTEXT_PATH}/sdm/sys/user/R";
                                        });
                                    } else {
                                        Metronic.unblockUI(el);
                                        Alice.showDefaultFailAlert(error, res);
                                    }
                                },
                                error: function (xhr, ajaxOptions, thrownError) {
                                    Metronic.unblockUI(el);
                                    Alice.showDefaultWarningGrowl("${getMessage('net.mayee.alice.error.data_error')}");
                                }
                            });
                        }
                    },
                    main: {
                        label: "${getMessage('net.mayee.alice.btn.cancel')}",
                        className: "default"
                    }
                }
            });
        });

    });

    function submitForm() {
        $('#form_2').submit();
    }
    /* 加载图片 */
    function loadPhoto(e) {
        var photoPath = e.value;
        var pos = photoPath.lastIndexOf(".");
        var lastname = photoPath.substring(pos, photoPath.length).toLowerCase();
        if (lastname != ".png"
                && lastname != ".jpg"
                && lastname != ".jpeg") {
            Alice.showDefaultFailAlertByText(error2, "${getMessage('net.mayee.alice.web.sys.user.choose_image.tip2')}");
            $("#savePhotoBtn").attr("disabled","disabled");
        }else{
            error2.hide("fast");
            $("#savePhotoBtn").removeAttr("disabled");
        }
    }

</script>
#end
#include ("/layout/layout_main.html")
